{include file="public/header"}
<body>
	<div class="sectionY">
		<a href="javascript:history.back();">
			<img src="__PUBLIC__/home/images/a19.png" alt="" class="a1">
		</a>
		<p class="p1">填写订单</p>
	</div>
	<div class="kong1" style=""></div>
	<form action="">
		<div class="tian_section1">
			<div class="container">
				<div class="a1">
					<input type="hidden" name="send_name" value="{$order.def_address.name|default=''}">
					<input type="hidden" name="send_mobile" value="{$order.def_address.mobile|default=''}">
					<input type="hidden" name="send_address" value="{$order.def_address.procity|default=''}{$order.def_address.address|default=''}">
					{if !empty($order.def_address)}
					<a data-href="{:url('Order/selectAddress')}" href="javascript:;" class="selectAddress">
						<img src="__PUBLIC__/home/images/a39.png" alt="" class="str_btn">
						<div class="u1">
							<img src="__PUBLIC__/home/images/a38.png" alt="">
							<span class="s1">{$order.def_address.name}</span>
							<span class="s1">{$order.def_address.mobile}</span>
						</div>
						<div class="u2">
							<p class="p1 chao2">
								{if $order.def_address.is_def eq 1}
								<span class="s1">默认</span>
								{/if}
								<span class="s2">{$order.def_address.procity}{$order.def_address.address}</span>
							</p>
						</div>
					</a>
					{else/}
					<a data-href="{:url('Order/selectAddress')}" href="javascript:;" class="selectAddress">
						<img src="__PUBLIC__/home/images/a39.png" alt="" class="str_btn" style="top: 2px;">
						<div class="u2">
							<p class="p1 chao2" style="height: 22px;">
								<span class="s2">选择地址</span>
							</p>
						</div>
					</a>
					{/if}
				</div>
			</div>
		</div>
		<div class="ge"></div>
		<div class="tian_section2">
			<div class="f1 clearfix">
				<div class="car_section1">
					{foreach $order.good_list as $g}
					<input type="hidden" name="cart_id[]" value="{$g.cart_id}">
					<div class="a1 clearfix">
						<div class="logo">
							<img src="{$g.img_url}" alt="">
						</div>
						<div class="right clearfix" style="width: 71%">
							<p class="p1 chao2">{$g.good_title}</p>
							<div class="e1">
								<div class="a1_1">
									<span class="s1">￥{$g.price}</span>
								</div>
							</div>
						</div>
					</div>
					{/foreach}
					<div class="a2">
						<p class="p1">共:{$order.good_num}件</p>
					</div>
				</div>
			</div>
			<div class="f2 clearfix">
				<span class="s1">商品金额</span>
				<span class="s2">￥{$order.good_total}</span>
			</div>
			<div class="f2 clearfix">
				<span class="s1">运费</span>
				<span class="s3">￥{$order.send_fee}</span>
			</div>
			<div class="f2 clearfix">
				<span class="s1">积分</span>
				<span class="s4">共{$order.score}积分，可用{$order.allow_score}，抵￥{$order.score_fee}</span>
				<input type="hidden" name="is_score" value="0">
				<img src="__PUBLIC__/home/images/switch_off.png" alt="" class="im1 score_fee">
				<img src="__PUBLIC__/home/images/switch_on.png" alt="" class=" im2 score_fee on">
			</div>
			<div class="f2 clearfix">
				<span class="s1">应付金额</span>
				<span class="s3 pay_money">￥{$order.total_price}</span>
			</div>
		</div>
		<div class="kong"></div>
		<div class="tian_foot">
			<div class="a1">
				<span class="s1 pay_money">￥{$order.total_price}</span>
			</div>
			<div class="a2">
				<a href="javascript:;" id="submit" data-status="0">去支付</a>
			</div>
		</div>
	</form>
</body>
<script>
	var total_price = parseFloat("{$order.total_price}"), score_fee=parseFloat("{$order.score_fee}");
	$(function(){
		$(".im1").click(function(){
			$(this).hide().siblings(".im2").show();
			calPrice();
		})
		$(".im2").click(function(){
			$(this).hide().siblings(".im1").show()
			calPrice()
		})

		$(".selectAddress").click(function () {
			let redirect_url = Base64.encode(location.href);
			location.href=$(this).data("href")+"?redirect_url="+redirect_url;
		})
		
		$("#submit").click(function () {
			let data = $("form").serialize(), o=this;
			if($(o).data("status")==1){
				return;
			}else{
				$(o).data("status", 1);
				$(o).css("background", "#aaa");
				let index = modal.loading();
				$.post("{:url('createOrder')}", data, function (res) {
					modal.close(index);
					modal.msg(res.result_info);
					if(res.result_code == 0){
						location.replace(res.result_data);
					}else{
						$(o).data("status", 0);
						$(o).css("background", "#ff4546");
					}
				});
			}
		});
	})
	function calPrice() {
		if($(".score_fee:visible").hasClass("on")){
			total_price = total_price-score_fee;
			$("input[name='is_score']").val(1);
			$(".pay_money").text("￥"+total_price);
		}else{
			total_price = total_price+score_fee;
			$("input[name='is_score']").val(0);
			$(".pay_money").text("￥"+total_price);
		}
	}
</script>
</html>